var services = angular.module('services', []);
/**
 * 定位相关服务
 **/
services.service('locationService', function ($http, $q) {
    /**
     * 定位
     **/
    this.getCurrentPosition = function () {

        var opt = {enableHighAccuracy: true, timeout: 3000, maximumAge: 60 * 60 * 1000};

        var deferred = $q.defer();

        navigator.geolocation.getCurrentPosition(function (position) {

            var coord = GPS.gcj_encrypt(position.coords.latitude, position.coords.longitude);
            coord = GPS.bd_encrypt(coord.lat, coord.lon);

            deferred.resolve({
                                 latitude: coord.lat,
                                 longitude: coord.lon
                             });

        }, function (error) {
            deferred.reject(error);
        }, opt);

        return deferred.promise;
    }

    /**
     * 百度搜索
     */
    this.placeSearch = function (keyword, region) {

        var params = {
            ak: 'aginFExNKbxLl2Sxoyria1wrOGjMpa1B',
            region: region,
            query: keyword,
            output: 'json',
            callback: 'JSON_CALLBACK'
        }

        var promise = $http.jsonp("https://api.map.baidu.com/place/v2/search", {
            method: 'GET',
            params: params,
            responseType: 'json'
        });

        return promise;

    }

    /**
     * 逆地理位置编码
     **/
    this.geocoder = function (coords) {

        var params = {
            ak: 'aginFExNKbxLl2Sxoyria1wrOGjMpa1B',
            location: coords.latitude + "," + coords.longitude,
            coordtype: 'bd09ll',
            output: 'json',
            pois: 1,
            callback: 'JSON_CALLBACK'
        }

        var deferred = $q.defer();

        $http.jsonp('https://api.map.baidu.com/geocoder/v2/', {
            method: 'GET',
            params: params,
            responseType: 'json'
        }).then(function (req) {

            if (req.data.status == 0) {
                var result = req.data.result;
                deferred.resolve(result);
            } else {
                deferred.reject(req);
            }

        }).then(function (error) {
            deferred.reject(error);
        });

        return deferred.promise;
    }
    /**
     * 翻译百度名称
     * @param coords
     * @returns {d.promise|*|promise|h.promise}
     */
    this.geocoderFromBaidu = function (coords) {

        var params = {
            ak: 'aginFExNKbxLl2Sxoyria1wrOGjMpa1B',
            location: coords.latitude + "," + coords.longitude,
            coordtype: 'bd09ll',
            output: 'json',
            pois: 1,
            callback: 'JSON_CALLBACK'
        }

        var deferred = $q.defer();

        $http.jsonp('https://api.map.baidu.com/geocoder/v2/', {
            method: 'GET',
            params: params,
            responseType: 'json'
        }).then(function (req) {

            if (req.data.status == 0) {
                var result = req.data.result;
                deferred.resolve(result);
            } else {
                deferred.reject(req);
            }

        }).then(function (error) {
            deferred.reject(error);
        });

        return deferred.promise;
    }

    /**
     * 选择最好的POI点
     *
     * @param pois
     * @returns {*}
     */
    this.chooseBestPoi = function (pois) {

        var best = null;

        if (pois.length > 0) {

            best = pois[0];

            for (var i = 0; i < pois.length; i++) {
                if (parseFloat(best.distance) > parseFloat(pois[i].distance)) {
                    best = pois[i];
                }
            }

        }

        return best;
    }

    //定位自己的位置
    this.locateMe = function (scope) {

        var me = this;

        //mock location

        /*scope.currentLocation = {
            name: '翰林世家',
            address: '锦绣大道南段99号',
            city: '成都市',
            point: {
                lat: '103.819169',
                lng: '30.676729'
            }
        }*/

        var deferred = $q.defer();

        if (scope.currentLocation) {

            deferred.resolve(scope.currentLocation);

        } else {

            var promise = me.getCurrentPosition();

            promise.then(function (coords) {

                me.geocoder(coords).then(function (data) {

                    var addressComponent = data.addressComponent;
                    var best = me.chooseBestPoi(data.pois);

                    if (null != best) {

                        scope.currentLocation = {
                            name: best.name,
                            address: best.addr,
                            city: addressComponent.city,
                            point: {
                                lat: best.point.y,
                                lng: best.point.x
                            }
                        }

                    } else {

                        var address = addressComponent.street + addressComponent.street_number;

                        scope.currentLocation = {
                            name: address,
                            address: address,
                            city: addressComponent.city,
                            point: data.location
                        }
                    }

                    deferred.resolve(scope.currentLocation);

                });

            }, function (error) {
                deferred.reject(error);
            });
        }

        return deferred.promise;
    }
});

/**
 * 微信设置服务
 **/
services.service('settingService', function ($http, $q) {
    /**
     * 获取服务信息
     **/
    this.getServices = function (sysKey) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/getServices.json',
                  method: 'GET',
                  params: {'appkey': sysKey},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {
            deferred.reject(status);
        });

        return deferred.promise;
    }
    /**
     * 获取微信验证信息
     *
     * @param sysKey
     * @param appId
     * @param code
     * @returns {d.promise|*|promise|h.promise}
     */
    this.authInfo = function (sysKey, appId, code) {

        var deferred = $q.defer();

        var params = {'appKey': sysKey, 'appid': appId, 'code': code};

        $http({
                  url: 'h5/authInfo.json',
                  method: 'GET',
                  params: params,
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }

});

/**
 * 代驾服务
 **/
services.service('daijiaService', function ($http, $q) {
    /**
     * 查询附近的司机
     *
     * @param sysKey
     * @param lat
     * @param lng
     * @returns {*|d.promise|promise}
     */
    this.coutNearDrivers = function (sysKey, lat, lng) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/dj/coutNearDrivers.json',
                  method: 'GET',
                  params: {'appkey': sysKey, 'lat': lat, 'lng': lng},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 预算费用
     *
     * @param sysKey
     * @param ack
     * @param passengerId
     * @param beginLat
     * @param beginLng
     * @param endLat
     * @param endLng
     * @returns {*|d.promise|promise}
     */
    this.calculation = function (sysKey, ack, passengerId, beginLat, beginLng, endLat, endLng) {

        var deferred = $q.defer();

        var params = {
            'appkey': sysKey,
            'startLat': beginLat,
            'startLng': beginLng,
            'endLat': endLat,
            'endLng': endLng
        };

        if (ack) {
            params['ack'] = ack;
        }
        if (passengerId) {
            params['passengerId'] = passengerId;
        }

        $http({
                  url: 'h5/v2/dj/calculationPrice.json',
                  method: 'GET',
                  params: params,
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }

    this.queryarea = function (appKey, ack, passengerId, lat, lng) {

        var deferred = $q.defer();

        var params = {
            'appkey': appKey,
            'lat': lat,
            'lng': lng
        };

        if (ack) {
            params['ack'] = ack;
        }

        if (passengerId) {
            params['passengerId'] = passengerId;
        }

        $http({
                  url: 'h5/v2/dj/queryArea.json',
                  method: 'GET',
                  params: params,
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }

    /**
     * 预约代驾订单
     *
     * @param sysKey
     * @param ack
     * @param beginAddress
     * @param beginAddressDetail
     * @param beginLat
     * @param beginLng
     * @param endAddress
     * @param endAddressDetail
     * @param endLat
     * @param endLng
     * @param phone
     * @param openId
     * @returns {d.promise|*|promise|h.promise}
     */
    this.makeAnAppointment =
        function (sysKey, ack, beginAddress, beginAddressDetail, beginLat, beginLng, endAddress,
                  endAddressDetail, endLat, endLng, phone, openId) {

            var params = {
                "appkey": sysKey,
                "ack": ack,
                "beginAddress": beginAddress,
                "beginAddressDetail": beginAddressDetail,
                "beginLat": beginLat,
                "beginLng": beginLng,
                "endAddress": endAddress,
                "endAddressDetail": endAddressDetail,
                "endLat": endLat,
                "endLng": endLng,
                "phone": phone,
                "openId": openId
            }

            var deferred = $q.defer();

            $http({
                      url: 'h5/v2/dj/makeAnAppointment.json',
                      method: 'POST',
                      params: params,
                      responseType: 'json'
                  }).success(function (data, header, config, status) {

                deferred.resolve(data);

            }).error(function (data, header, config, status) {

                deferred.reject(status);

            });

            return deferred.promise;

        }
    /**
     * 查询订单信息
     *
     * @param sysKey
     * @param orderId
     */
    this.findOrder = function (sysKey, orderId) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/dj/findOrder.json',
                  method: 'GET',
                  params: {'appkey': sysKey, 'orderId': orderId},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }
    /**
     * 取消代驾订单
     *
     * @param sysKey
     * @param orderId
     * @param reson
     * @returns {*|d.promise|promise}
     */
    this.cancelOrder = function (sysKey, orderId, reson) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/dj/cancelOrder.json',
                  method: 'POST',
                  params: {'appkey': sysKey, 'orderId': orderId, 'reson': reson},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }
    /**
     * 获取支付信息
     *
     * @param syskey
     * @param orderId
     * @returns {d.promise|*|promise|h.promise}
     */
    this.prepay = function (syskey, orderId) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/dj/prepay.json',
                  method: 'GET',
                  params: {'appkey': syskey, 'orderId': orderId},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 检查订单是否已经被支付
     *
     * @param syskey
     * @param orderId
     * @returns {d.promise|*|promise|h.promise}
     */
    this.hasPayed = function (syskey, orderId) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/dj/hasPayed.json',
                  method: 'GET',
                  params: {'appkey': syskey, 'orderId': orderId},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 支付 (余额 或 签单)
     *
     * @param syskey
     * @param orderId
     * @returns {d.promise|*|promise|h.promise}
     */
    this.doPay = function (syskey, orderId, payType) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/dj/doPay.json',
                  method: 'POST',
                  params: {'appkey': syskey, 'orderId': orderId, 'payType': payType},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 微信支付
     *
     * @param syskey
     * @param orderId
     * @param openid
     * @param appid
     * @param uri
     * @returns {d.promise|*|promise|h.promise}
     */
    this.doPayForWx = function (syskey, orderId, openid, appid, uri) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/dj/doPayForWx.json',
                  method: 'POST',
                  params: {'appkey': syskey, 'orderId': orderId, 'openid': openid, 'appid': appid},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }

});
/**
 * 用户服务
 **/
services.service('userService', function ($http, $q) {
    /**
     * 检查用户是否已经与微信账号进行了绑定
     *
     * @param wxAppId
     * @param sysKey
     * @param phone
     * @param openId
     * @returns {*|d.promise|promise}
     */
    this.checkBind = function (wxAppId, sysKey, phone, openId) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/checkBind.json',
                  method: 'POST',
                  params: {'appkey': sysKey, 'appid': wxAppId, 'phone': phone, 'openId': openId},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 检查验证码是否正确
     *
     * @param wxAppId
     * @param sysKey
     * @param phone
     * @param openId
     * @returns {*|d.promise|promise}
     */
    this.checkCode = function (wxAppId, sysKey, phone, vcode, openId, city) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/checkCode.json',
                  method: 'POST',
                  params: {
                      'appkey': sysKey,
                      'appid': wxAppId,
                      'phone': phone,
                      'vcode': vcode,
                      'openId': openId,
                      'city': city
                  },
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }
    /**
     * 查询绑定用户
     *
     * @param appKey
     * @param openId
     * @returns {d.promise|*|promise|h.promise}
     */
    this.findWxBind = function (appKey, openId) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/findWxBind.json',
                  params: {'appKey': appKey, 'openId': openId},
                  method: 'GET',
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }
    /**
     * 获取验证码
     *
     * @param appkey
     * @param phone
     * @returns {d.promise|*|promise|h.promise}
     */
    this.sendVCode = function (appkey, phone) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/sendVCode.json',
                  params: {'appkey': appkey, 'phone': phone},
                  method: 'GET',
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 加载服务协议
     *
     * @param appkey
     * @returns {d.promise|*|promise|h.promise}
     */
    this.getAgreement = function (appkey) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/getAgreement.json',
                  params: {'appkey': appkey},
                  method: 'GET',
                  responseType: 'text'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }

});

/**
 * 专车服务
 */
services.service('zhuancheService', function ($http, $q) {
    /**
     * 查询车辆类型
     *
     * @returns {*|d.promise|promise}
     */
    this.getCarTypes = function (appkey, ack, passengerId, lat, lng) {

        var deferred = $q.defer();

        $http({

                  url: 'h5/v2/zhuanche/getCarTypes.json',
                  method: 'GET',
                  params: {
                      'appkey': appkey,
                      'passengerId': passengerId,
                      'lat': lat,
                      'lng': lng,
                      'ack': ack
                  },
                  responseType: 'json'

              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }

    /**
     * 查询附近的司机
     *
     * @param sysKey
     * @param lat
     * @param lng
     * @returns {*|d.promise|promise}
     */
    this.coutNearDrivers = function (sysKey, lat, lng, carType) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/zhuanche/coutNearDrivers.json',
                  method: 'GET',
                  params: {'appkey': sysKey, 'lat': lat, 'lng': lng, 'carType': carType},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 预算专车费用
     *
     * @param sysKey
     * @param carTypeId
     * @param beginLat
     * @param beginLng
     * @param endLat
     * @param endLng
     * @returns {*|d.promise|promise}
     */
    this.calculation = function (sysKey, carTypeId, beginLat, beginLng, endLat, endLng) {

        var deferred = $q.defer();

        var params = {
            'appkey': sysKey,
            'carTypeId': carTypeId,
            'startLat': beginLat,
            'startLng': beginLng,
            'endLat': endLat,
            'endLng': endLng
        };

        $http({
                  url: 'h5/v2/zhuanche/calculationPrice.json',
                  method: 'GET',
                  params: params,
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }

    /**
     * 预约专车订单
     *
     * @param sysKey
     * @param ack
     * @param beginAddress
     * @param beginAddressDetail
     * @param beginLat
     * @param beginLng
     * @param endAddress
     * @param endAddressDetail
     * @param endLat
     * @param endLng
     * @param phone
     * @param openId
     * @param carTypeId
     * @returns {*|d.promise|promise}
     */
    this.makeAnAppointment =
        function (sysKey, ack, beginAddress, beginAddressDetail, beginLat, beginLng, endAddress,
                  endAddressDetail, endLat, endLng, phone, openId, carTypeId) {

            var params = {
                "appkey": sysKey,
                "ack": ack,
                "beginAddress": beginAddress,
                "beginAddressDetail": beginAddressDetail,
                "beginLat": beginLat,
                "beginLng": beginLng,
                "endAddress": endAddress,
                "endAddressDetail": endAddressDetail,
                "endLat": endLat,
                "endLng": endLng,
                "phone": phone,
                "openId": openId,
                'carTypeId': carTypeId
            }

            var deferred = $q.defer();

            $http({
                      url: 'h5/v2/zhuanche/makeAnAppointment.json',
                      method: 'POST',
                      params: params,
                      responseType: 'json'
                  }).success(function (data, header, config, status) {

                deferred.resolve(data);

            }).error(function (data, header, config, status) {

                deferred.reject(status);

            });

            return deferred.promise;

        }

    /**
     * 查询订单信息
     *
     * @param sysKey
     * @param orderId
     */
    this.findOrder = function (sysKey, orderId) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/zhuanche/findOrder.json',
                  method: 'GET',
                  params: {'appkey': sysKey, 'orderId': orderId},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }
    /**
     * 取消订单
     *
     * @param sysKey
     * @param orderId
     * @param reson
     * @returns {*|d.promise|promise}
     */
    this.cancelOrder = function (sysKey, orderId, reson) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/zhuanche/cancelOrder.json',
                  method: 'POST',
                  params: {'appkey': sysKey, 'orderId': orderId, 'reson': reson},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }

    /**
     * 获取支付信息
     *
     * @param syskey
     * @param orderId
     * @returns {d.promise|*|promise|h.promise}
     */
    this.prepay = function (syskey, orderId) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/zhuanche/prepay.json',
                  method: 'GET',
                  params: {'appkey': syskey, 'orderId': orderId},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 检查订单是否已经被支付
     *
     * @param syskey
     * @param orderId
     * @returns {d.promise|*|promise|h.promise}
     */
    this.hasPayed = function (syskey, orderId) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/zhuanche/hasPayed.json',
                  method: 'GET',
                  params: {'appkey': syskey, 'orderId': orderId},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 支付 (余额 或 签单)
     *
     * @param syskey
     * @param orderId
     * @returns {d.promise|*|promise|h.promise}
     */
    this.doPay = function (syskey, orderId, payType) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/zhuanche/doPay.json',
                  method: 'POST',
                  params: {'appkey': syskey, 'orderId': orderId, 'payType': payType},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 微信支付
     *
     * @param syskey
     * @param orderId
     * @param openid
     * @param appid
     * @param uri
     * @returns {d.promise|*|promise|h.promise}
     */
    this.doPayForWx = function (syskey, orderId, openid, appid, uri) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/v2/zhuanche/doPayForWx.json',
                  method: 'POST',
                  params: {'appkey': syskey, 'orderId': orderId, 'openid': openid, 'appid': appid},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
});

/**
 * 司机服务
 */
services.service('driverService', function ($http, $q) {
    /**
     * 查询司机信息
     *
     * @param sysKey
     * @param driverId
     * @returns {d.promise|*|promise|h.promise}
     */
    this.findDriver = function (sysKey, driverId) {

        var deferred = $q.defer();

        $http({
                  url: 'h5/findDriver.json',
                  method: "GET",
                  params: {'appkey': sysKey, 'driverId': driverId},
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;

    }

});

/**
 * 跑腿服务
 */
services.service('paotuiService', function ($http, $q) {
    /**
     * 预估价格
     *
     * @param appKey
     * @param ack
     * @param city
     * @param passengerId
     * @param startLat
     * @param startLng
     * @param endLat
     * @param endLng
     * @returns {d.promise|*|promise|h.promise}
     */
    this.budget = function (appKey, ack, city, passengerId, startLat, startLng, endLat, endLng) {

        var deferred = $q.defer();

        var params = {
            'appkey': appKey,
            'ack': ack,
            'city': city,
            'passengerId': passengerId,
            'startLat': startLat,
            'startLng': startLng,
            'endLat': endLat,
            'endLng': endLng
        }

        $http({
                  url: 'h5/v2/pt/calculationPrice.json',
                  params: params,
                  method: "GET",
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {

            deferred.reject(status);

        });

        return deferred.promise;
    }
    /**
     * 创建跑腿订单
     *
     * @param title
     * @param content
     * @param deliverTime
     * @param deliverAddress
     * @param deliverLat
     * @param deliverLng
     * @param passengerPhone
     * @param openId
     * @param passengerId 可选
     * @param shouldPay 可选
     * @param startTime 可选
     * @param startPhone 可选
     * @param endPhone 可选
     * @param startAddress 可选
     * @param startLat 可选
     * @param startLng 可选
     * @param orderType 可选
     * @param travelTime 可选
     * @param mileage 可选
     * @param startPrice 可选
     * @param mileagePrice 可选
     * @param travelTimePrice 可选
     * @param appKey
     */
    this.makeAnAppointment = function (title, content, deliverTime, deliverAddress, deliverLat,
                                       deliverLng, passengerPhone, openId, passengerId, shouldPay,
                                       startTime, startPhone, endPhone, startAddress, startLat,
                                       startLng, orderType, travelTime, mileage, startPrice,
                                       mileagePrice, travelTimePrice, appkey) {

        var deferred = $q.defer();

        var params = {
            'appkey': appkey,
            'title': title,
            'content': content,
            'deliverTime': deliverTime,
            'deliverAddress': deliverAddress,
            'deliverLat': deliverLat,
            'deliverLng': deliverLng,
            'phone': passengerPhone,
            'openId': openId,
            'passengerId': passengerId,
            'shouldPay': shouldPay,
            'startTime': startTime,
            'startPhone': startPhone,
            'endPhone': endPhone,
            'startAddress': startAddress,
            'startLat': startLat,
            'startLng': startLng,
            'orderType': orderType,
            'travelTime': travelTime,
            'mileage': mileage,
            'startPrice': startPrice,
            'mileagePrice': mileagePrice,
            'travelTimePrice': travelTimePrice
        };

        $http({
                  url: 'h5/v2/pt/makeAnAppointment.json',
                  params: params,
                  method: "POST",
                  responseType: 'json'
              }).success(function (data, header, config, status) {

            deferred.resolve(data);

        }).error(function (data, header, config, status) {
            deferred.reject(status);

        });

        return deferred.promise;

    }

});